﻿using System;
// This Package
// 负责服务端到客户端的数据封装
// 格式参见http://srv-001/trac/wiki/phoneapi


// 使用实例:
//  JsonResultObj result = new JsonResultObj()
//  {
//      Result = ResultStatusCode.Error,
//      Content = new ErrorData()
//      {
//          ErrorCode = 20002,
//          Error = "Hello This is an Error", 
//      }
//  };
//  return Json(result, JsonRequestBehavior.AllowGet);

namespace com.hyrentals.webcommon.api
{
    /// <summary>
    /// Json 结构的封装
    /// </summary>
    public class JsonResultObj
    {
        public ResultStatusCode Result { get; set; }

        public object Content { get; set; }
    }

    /// <summary>
    /// the object when ResultStatusCode == 1
    /// </summary>
    public class ErrorData
    {
        public ComponentType ComponentType { set; private get; }     //错误来自的模块

        public uint ErrorId { set; private get; }                    //错误在模块中的编号

        public string ErrorCode
        {
            get
            {
                return string.Format("{0:D2}{1:D2}", Convert.ToUInt32(ComponentType), ErrorId);
            }
        }

        public string ErrorMsg { get; set; }
    }

    public class KISSYValidationJsonResultObj
    {
        public uint state { get; set; }
        public string message { get; set; }
    }

    #region Enum
    /// <summary>
    /// status code:
    ///     0 - success
    ///     1 - error
    /// </summary>
    public enum ResultStatusCode : uint
    {
        Success = 0,
        Error = 1,
    }

    public enum StatusCodeEnum : int
    {
        OK = 200,
        BadRequest = 400,
        Unauthorized = 401,
        Forbidden = 403,
        NotFound = 404,
        InternalServerError = 500,
    }

    public enum ComponentType : byte
    {
        Account = 0,
        Home = 1,
        RV = 2,
        Search = 3,
        Image = 4,
        Member = 5,

        Unknown = 99,
    }

    public enum CommonErrorId : uint
    {
        UncaughtException = 1,
        Unauhtorized = 2,
        BadArguments = 3,
        InternalError = 4,

        MaxValue = 16,
        MinUserErrorId = 17,
    }

    /// <summary>
    /// result type
    /// </summary>
    public enum ResultDataType : uint
    {
        Html = 1,
        Json = 2,
        Text = 3,
        Xml = 4,
        Javascript = 5,
        File = 6,
        ProtoBuf = 7,
    }

    public enum KISSYValidationSign : uint
    {
        Error = 0,
        OK = 1,
        Hint = 2,
        Ignore = 3
    }

   

    #endregion
}
